// 管理账号信息
const USERS_KEY = 'USERS_KEY_001';
const STATE_KEY = 'STATE_KEY_001';

const getUsers = function () {
    let ret = '';
    ret = uni.getStorageSync(USERS_KEY);
    if (!ret) {
        ret = '[]';
    }
    return JSON.parse(ret);
}

const addUser = function (userInfo) {
	console.log(JSON.stringify(userInfo));
//     let users = getUsers();
//     users.push({
// 		// 存储服务器端返回的信息
//         data: userInfo 
//     });
    uni.setStorageSync(USERS_KEY, JSON.stringify(userInfo));
}
function http(url,method,data,callBack){
	console.log("url=" + url);
		var that=this;
		uni.request({
			url:url, 
			method:method,
			data:data,
			header: {
				'content-type': 'json' //自定义请求头信息
			},
			success: function(res) {
				if(res.data.code===1){
					callBack(res.data.data);
				}else{
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
				}				
			},
			fail: function(err) {
				console.log(err)
			}
		});
	};
	
function converToCastString(casts){
	var castsjoin="";
	for(var idx in casts){
		castsjoin=castsjoin+casts[idx].name+"/";
	};
	return castsjoin.substring(0,castsjoin.length-2);
};

function converToCastInfos(casts){
	var castsArray=[];
	for(var idx in casts){
		var cast={
			img:casts[idx].avatars?casts[idx].avatars.large:"",
			name:casts[idx].name
		}
		castsArray.push(cast);
	};
	return castsArray;
};

function PullToRefresh(e){
	var pullDate={
		top:0,
		startyY:0,
		touching:false
	};
	function craetWarp(e){
		//先在下拉元素上创建个盒子
		
	};
	function touchStart(e){//触摸开始的时候触发
		pullDate.startyY=e.targetTouches[0].pageY;
		pullDate.touching=true;	
		console.log(e.offsetTop);
	};
	function touchMove(e){//手指在屏幕上滑动的时候触发
	};
	function toucHend(){//触摸结束的时候触发
		
	};
};	

export default {
    getUsers,
    addUser,
    http,
    converToCastString,
    converToCastInfos
}
